<%@page import="co.gov.medellin.ssti.sub.common.util.Utility"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isELIgnored="false"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/displaytag-11.tld" prefix="display"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*"%>
<%@ page
	import="co.gov.medellin.ssti.sub.model.vo.AtributoVO,co.gov.medellin.ssti.sub.model.vo.ModificarBOTVO"%>
<%@ page import="co.gov.medellin.ssti.sub.model.vo.ValorFlexibleVO"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript"
	src="<%= request.getContextPath() + "/js/popUP.js" %>"></script>
<link href="<%= request.getContextPath() + "/css/bloques.css" %>"
	rel="stylesheet" type="text/css">
<link href="<%= request.getContextPath() + "/css/table.css" %>"
	rel="stylesheet" type="text/css">
<script src="<%=request.getContextPath()%>/js/dateValidation.js"
	type="text/javascript"></script>
<script type="text/javascript"
	src="<%=request.getContextPath() + "/js/jquery-1.8.0.js"%>"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()
					+ "/js/jquery-ui-1.10.3.custom.min.js"%>"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()
					+ "/js/jquery.ui.datepicker-es.js"%>"></script>
<link rel="stylesheet"
	href="<%=request.getContextPath()
					+ "/css/ui-lightness/jquery-ui-1.10.3.custom.css"%>" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
$(document).ready(function() {
	$("input[id='operacion']").val('');
	
	var fechaActual = new Date();
    var dd = fechaActual.getDate();
    var mm = fechaActual.getMonth()+1; // indice 0
    var yyyy = fechaActual.getFullYear();
    if(dd<10){dd='0'+dd;} if(mm<10){mm='0'+mm;} var fechaActual = dd+'/'+mm+'/'+yyyy;
    
	$("#guardarBtn").click(function(){	
		$("#mainForm").attr('target','_self');
		var fDate = isDate($("#date").val());
		if(!fDate){
			alert('Fecha de otorgacion no valida.');
			return false;
		}
		if($("#sede").val() == ''){
			alert("Debe elegir una sede.");
			return false;
		}
		$("input[id='operacion']").val('<%= Utility.OP_GUARDAR %>');
		$("#mainForm").attr('','');
		$("#mainForm").submit();					
	});
	
});
</script>

<!-- DatePickers -->
<script type="text/javascript">
$.datepicker.setDefaults({
	  showOn: "button",
	  buttonImageOnly: true,
	  buttonImage: "<%=request.getContextPath() + "/images/Calendar.png"%>",
	  buttonText : "Calendario"
	});
	$(function() {
		$("#date").datepicker({
			changeMonth : true,
			changeYear : true
		});
		$('.fecha').datepicker({
			changeMonth : true,
			changeYear : true,
			showOn: "button",
			buttonImageOnly: true,
			buttonImage: "<%=request.getContextPath() + "/images/Calendar.png"%>",
							buttonText : "Calendario"
		});
	});
</script>
<title>Modificacion Beneficio Otorgado</title>

<script type="text/javascript">    
function habilitaf(nombre){
	document.forms['frmIngresoDatos'].elements[nombre].disabled=false;
}
    
function habilita(){
	if(document.frmIngresoDatos.cooperativa.value == "S"){
    	document.frmIngresoDatos.tercero.disabled = false; 
    }else{
      	document.frmIngresoDatos.tercero.disabled = true;
     	document.frmIngresoDatos.tercero.value = "";
    }
}
 

function onlyNumbers(field) {
	var regex = /\d/g;
    var text = $(field).val();
    if (regex(text)) {
    	alert("El Campo es Numerico");
        field.focus();
        field.select();
	}    
}
    
function onlyLetters(field) {
	if(field.val() != "" && field.val().match(/^[a-zA-Z]$/) !== null){
		
	}else{
		alert("El Campo es solo letras (A-Z)");
		field.focus();
	    field.select();
	}
    var valid = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz";
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
    }

}
</script>
</head>
<body>
	<html:form action="empresas/ValidarRenovarBOT.do" method="post" styleId="mainForm"
		type="co.gov.medellin.ssti.sub.web.form.ValidarBOTEmpresaForm">
		<html:hidden name="ValidarBOTEmpresaForm" property="codigoBeneficio" />
		<html:hidden name="ValidarBOTEmpresaForm" property="codigoEmpresa" />
		<html:hidden name="ValidarBOTEmpresaForm" property="codigoBOT" />
		<html:hidden name="ValidarBOTEmpresaForm" property="operacion" styleId="operacion" />
		<!--<html:hidden name="ValidarBOTEmpresaForm" property="codigoSede" />-->
		
		<c:set var="valor" scope="request" value=""/>

		<c:if test="${empty ValidarBOTEmpresaForm.sedes }">
			<div align="center">Verifique la vigencia del Beneficio.</div>
		</c:if>

		<c:if test="${not empty ValidarBOTEmpresaForm.sedes}">
			<c:if test="${empty ValidarBOTEmpresaForm.empresaVO.codigo}">
				<tr>
					<td class="titulosenblanco" colspan="3">
						No se encontr&oacute; el beneficiario al que se le otorgar&aacute; un beneficio.
					</td>
				</tr>
			</c:if>
						
			<table style="width: 100%;text-align: center;">
				<c:if test="${not empty ValidarBOTEmpresaForm.empresaVO.codigo}">
					<tr>
						<td class="titulosenblanco" colspan="3">
							Modificaci&oacute;n del Beneficio Otorgado
							<br>${ValidarBOTEmpresaForm.subprogramaVO.nombre}
						</td>
					</tr>
					<tr>
						<td class="titulosenblanco" colspan="3">&nbsp;</td>
					</tr>
					<tr>
						<td class="titulosenblanco" colspan="3">
							<DIV align="center">Empresa</DIV>
						</td>
					</tr>
					<tr>
						<td class="titulosenblanco" colspan="3">&nbsp;</td>
					</tr>					
						<tr>
							<td class="celdatabla" width="15%">&nbsp;</td>
							<td class="celdatabla" width="30%">NIT:</td>
							<td class="celdatabla" width="40%">
								<div class="form">
									${ValidarBOTEmpresaForm.empresaVO.nit}									
								</div>
							</td>
						</tr>
						<tr>
							<td class="celdatabla" width="15%">&nbsp;</td>
							<td class="celdatabla" width="30%">Razon Social:</td>
							<td class="celdatabla" width="40%">
								<div class="form">
									${ValidarBOTEmpresaForm.empresaVO.razonSocial}																	
								</div>
							</td>
							<td class="celdatabla" width="45%">&nbsp;</td>
						</tr>
				
					<tr>
						<td class="titulosenblanco" colspan="2">&nbsp;</td>
					</tr>
					<tr>
						<td class="titulosenblanco">&nbsp;</td>
						<td class="titulosenblanco" colspan="2"><hr /></td>
					</tr>								

					<c:forEach var="atributo" items="${ValidarBOTEmpresaForm.atributos}">					
						<tr>
							<c:forEach var="resultado" items="${ValidarBOTEmpresaForm.resultados}">								
								<c:if test="${resultado.nombre eq atributo.nombre}">
									<c:set var="valor" scope="request" value="${resultado.valorInicial eq null ? '' : resultado.valorInicial}"/>
								</c:if>
								
							</c:forEach>
						</tr>
						
						<tr>
							<td class="celdatabla" width="15%">&nbsp;</td>
							<td align="left" class="celdatabla">
								${atributo.obligatorio == 'S' ? atributo.etiqueta.concat(' (*)') :
									atributo.etiqueta}
							</td>
							<c:choose>
								<c:when test="${atributo.valLista eq 'N'}">
									<c:choose>
										<c:when test="${atributo.tipodato eq 'F'}">
											<td align="left" class="celdatabla">
												<input type="text" id="Atri${atributo.codatributo}" class="fecha form" value="${valor}"
													name="Atri${atributo.codatributo}">
												<input type="hidden" name="fecha" />
												<input type="hidden" name="Atri${atributo.codatributo}" value="${atributo.codatributo}" />
											</td>										
										</c:when>
										<c:otherwise>
											<c:choose>
												<c:when test="${atributo.tipodato eq 'N'}">
													<c:choose>
														<c:when test="${atributo.descripcion eq 'EDAD'}">
															<input class="form" type="text" onblur="validate(this)"																
																name="Atri${atributo.codatributo}" />
														</c:when>
														<c:otherwise>
															<td align="left">
																<input Class="form" type="text" onblur="validate(this)"																	
																	name="Atri${atributo.codatributo}" value="${valor}" />
															</td>
														</c:otherwise>
													</c:choose>
												</c:when>
												<c:otherwise>
													<c:choose>
														<c:when test="${atributo.tipodato eq 'L'}">
															<td align="left">
																<input Class="form" type="text"
																	onblur="validateletras(this)"
																	maxlength="${atributo.longitud}"
																	name="Atri${atributo.codatributo}" />
															</td>
														</c:when>
														<c:otherwise>
															<td align="left">
																<input value="${valor}" class="form"
																	type="text" name="Atri${atributo.codatributo}" />
															</td>
														</c:otherwise>
													</c:choose>
												</c:otherwise>
											</c:choose>
										</c:otherwise>
									</c:choose>
								</c:when>
								<c:otherwise>
									<c:if test="${not empty atributo.valoresflexibles}">
										<td align="left">
											<select class="formlista" name="Atri${atributo.codatributo}">
												<c:forEach var="vflvo" items="${atributo.valoresflexibles}">
													<c:choose>
														<c:when test="${(vflvo.codigovfl eq valor) or (vflvo.descripciontvfl eq valor) }">															
															<option selected="selected" value="${vflvo.descripcionvf}">${vflvo.descripcionvf}</option>
														</c:when>
														<c:otherwise>
															<option value="${vflvo.descripcionvf}">${vflvo.descripcionvf}</option>
														</c:otherwise>
													</c:choose>																									
												</c:forEach>
											</select>
									</c:if>
									<c:if test="${empty atributo.valoresflexibles}">
										<td align="left">
											<input Class="form" type="text" name="Atri${atributo.codatributo}" />
										</td>
									</c:if>
								</c:otherwise>
							</c:choose>				          
					</c:forEach>
					
					<tr>
						<td class="celdatabla" width="15%">&nbsp;</td>
						<td align="left" class="celdatabla">
							VALOR DEL BENEFICIO
						</td>
						<td align="left">
							<input type="text" name="costbene" size="10" class="form" value="${ValidarBOTEmpresaForm.bot.valorBeneficio}" />
						</td>
					</tr>
					<tr>
						<td class="celdatabla" width="15%">&nbsp;</td>
						<td align="left" class="celdatabla">
							TIPO DE BENEFICIO
						</td>
						<td align="left">
							<input type="text" name="tipobene" size="75" class="form" value="${ValidarBOTEmpresaForm.bot.tipoBeneficio}"/>
						</td>
					</tr>
					<tr>
						<td class="celdatabla" width="25%">&nbsp;</td>
						<td class="celdatabla" width="31%" align="left">
							FECHA DE OTORGACI&Oacute;N:
						</td>
						<td align="left">
							<input type="text" class="form" name="date" id="date" value="${ValidarBOTEmpresaForm.bot.fechaBeneficio}" />
						</td>
					</tr>

					<tr>
						<td class="celdatabla" width="15%">&nbsp;</td>
						<td align="left" class="celdatabla">
							SEDE
						</td>
						<td align="left">
							<c:if test="${not empty ValidarBOTEmpresaForm.sedes}">							
								<html:select name="ValidarBOTEmpresaForm" property="codigoSede" styleId="sede"
									title="SEDE" styleClass="formlista" value="${ValidarBOTEmpresaForm.bot.sedeCodigo}" >
									<html:option value="">Seleccione una sede..</html:option>
									<html:optionsCollection name="ValidarBOTEmpresaForm" 
										property="sedes" label="nombre" value="code" />
								</html:select>
							</c:if>
						</td>
					
					</tr>


					<tr>
						<td class="titulosenblanco" colspan="3">&nbsp;</td>
					</tr>
					<tr>
						<td align="right">&nbsp;</td>
						<td colspan="2">
							<DIV align="center">
								<input type="submit" value="Guardar" name="guardarBtn" id="guardarBtn"/>
							</DIV>
						</td>
					</tr>
					
				</c:if>
	

			</table>
			<div align="center">			
				<html:link scope="request" 
					page="/empresas/DetalleBeneficios.do?codigoBeneficio=${ValidarBOTEmpresaForm.codigoBeneficio}
						&codigoEmpresa=${ValidarBOTEmpresaForm.empresaVO.codigo}">
					<img src="<%=request.getContextPath() + "/images/b_atras.gif"%>"
						width="24" height="15" border="0">
					<br>
					<span class="celdaayd">Atras</span>
				</html:link>		
			</div>
		</c:if>
	</html:form>
</body>
</html>